{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Lab 1\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Manipulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this lab, you will learn how to construct a simple machine learning model given a labelled dataset. We will be analysing the Indian Liver Patient Records Dataset, and we will be predicting whether a patient has a liver disease or not. Below you will see that some cells in the notebook contain the commented line *# TODO* for you to add your own code. Try to get this code working yourself and see how you get on. There are many resources on the Web that will help you. Sample code will be provided in an \"Answers\" version of this notebook at a later date."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Exploration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this step, we will be analyzing the data given to us. It gives us an idea of what features are important to the determination of liver disease. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Age</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Total_Bilirubin</th>\n",
       "      <th>Direct_Bilirubin</th>\n",
       "      <th>Alkaline_Phosphotase</th>\n",
       "      <th>Alamine_Aminotransferase</th>\n",
       "      <th>Aspartate_Aminotransferase</th>\n",
       "      <th>Total_Protiens</th>\n",
       "      <th>Albumin</th>\n",
       "      <th>Albumin_and_Globulin_Ratio</th>\n",
       "      <th>Dataset</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>65</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.1</td>\n",
       "      <td>187</td>\n",
       "      <td>16</td>\n",
       "      <td>18</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.3</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>62</td>\n",
       "      <td>Male</td>\n",
       "      <td>10.9</td>\n",
       "      <td>5.5</td>\n",
       "      <td>699</td>\n",
       "      <td>64</td>\n",
       "      <td>100</td>\n",
       "      <td>7.5</td>\n",
       "      <td>3.2</td>\n",
       "      <td>0.74</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>62</td>\n",
       "      <td>Male</td>\n",
       "      <td>7.3</td>\n",
       "      <td>4.1</td>\n",
       "      <td>490</td>\n",
       "      <td>60</td>\n",
       "      <td>68</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.3</td>\n",
       "      <td>0.89</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>58</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>182</td>\n",
       "      <td>14</td>\n",
       "      <td>20</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.4</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>3.9</td>\n",
       "      <td>2.0</td>\n",
       "      <td>195</td>\n",
       "      <td>27</td>\n",
       "      <td>59</td>\n",
       "      <td>7.3</td>\n",
       "      <td>2.4</td>\n",
       "      <td>0.40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>46</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.7</td>\n",
       "      <td>208</td>\n",
       "      <td>19</td>\n",
       "      <td>14</td>\n",
       "      <td>7.6</td>\n",
       "      <td>4.4</td>\n",
       "      <td>1.30</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>26</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.2</td>\n",
       "      <td>154</td>\n",
       "      <td>16</td>\n",
       "      <td>12</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.5</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>29</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.3</td>\n",
       "      <td>202</td>\n",
       "      <td>14</td>\n",
       "      <td>11</td>\n",
       "      <td>6.7</td>\n",
       "      <td>3.6</td>\n",
       "      <td>1.10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>17</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.3</td>\n",
       "      <td>202</td>\n",
       "      <td>22</td>\n",
       "      <td>19</td>\n",
       "      <td>7.4</td>\n",
       "      <td>4.1</td>\n",
       "      <td>1.20</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>55</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.2</td>\n",
       "      <td>290</td>\n",
       "      <td>53</td>\n",
       "      <td>58</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.4</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>57</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.1</td>\n",
       "      <td>210</td>\n",
       "      <td>51</td>\n",
       "      <td>59</td>\n",
       "      <td>5.9</td>\n",
       "      <td>2.7</td>\n",
       "      <td>0.80</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>72</td>\n",
       "      <td>Male</td>\n",
       "      <td>2.7</td>\n",
       "      <td>1.3</td>\n",
       "      <td>260</td>\n",
       "      <td>31</td>\n",
       "      <td>56</td>\n",
       "      <td>7.4</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>64</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.3</td>\n",
       "      <td>310</td>\n",
       "      <td>61</td>\n",
       "      <td>58</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.4</td>\n",
       "      <td>0.90</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>74</td>\n",
       "      <td>Female</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.4</td>\n",
       "      <td>214</td>\n",
       "      <td>22</td>\n",
       "      <td>30</td>\n",
       "      <td>8.1</td>\n",
       "      <td>4.1</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>61</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.2</td>\n",
       "      <td>145</td>\n",
       "      <td>53</td>\n",
       "      <td>41</td>\n",
       "      <td>5.8</td>\n",
       "      <td>2.7</td>\n",
       "      <td>0.87</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>25</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.1</td>\n",
       "      <td>183</td>\n",
       "      <td>91</td>\n",
       "      <td>53</td>\n",
       "      <td>5.5</td>\n",
       "      <td>2.3</td>\n",
       "      <td>0.70</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>38</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.8</td>\n",
       "      <td>342</td>\n",
       "      <td>168</td>\n",
       "      <td>441</td>\n",
       "      <td>7.6</td>\n",
       "      <td>4.4</td>\n",
       "      <td>1.30</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>33</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.6</td>\n",
       "      <td>0.5</td>\n",
       "      <td>165</td>\n",
       "      <td>15</td>\n",
       "      <td>23</td>\n",
       "      <td>7.3</td>\n",
       "      <td>3.5</td>\n",
       "      <td>0.92</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>40</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.3</td>\n",
       "      <td>293</td>\n",
       "      <td>232</td>\n",
       "      <td>245</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.1</td>\n",
       "      <td>0.80</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>40</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.3</td>\n",
       "      <td>293</td>\n",
       "      <td>232</td>\n",
       "      <td>245</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.1</td>\n",
       "      <td>0.80</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>51</td>\n",
       "      <td>Male</td>\n",
       "      <td>2.2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>610</td>\n",
       "      <td>17</td>\n",
       "      <td>28</td>\n",
       "      <td>7.3</td>\n",
       "      <td>2.6</td>\n",
       "      <td>0.55</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>51</td>\n",
       "      <td>Male</td>\n",
       "      <td>2.9</td>\n",
       "      <td>1.3</td>\n",
       "      <td>482</td>\n",
       "      <td>22</td>\n",
       "      <td>34</td>\n",
       "      <td>7.0</td>\n",
       "      <td>2.4</td>\n",
       "      <td>0.50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>62</td>\n",
       "      <td>Male</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.0</td>\n",
       "      <td>542</td>\n",
       "      <td>116</td>\n",
       "      <td>66</td>\n",
       "      <td>6.4</td>\n",
       "      <td>3.1</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>40</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.9</td>\n",
       "      <td>1.0</td>\n",
       "      <td>231</td>\n",
       "      <td>16</td>\n",
       "      <td>55</td>\n",
       "      <td>4.3</td>\n",
       "      <td>1.6</td>\n",
       "      <td>0.60</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>63</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.2</td>\n",
       "      <td>194</td>\n",
       "      <td>52</td>\n",
       "      <td>45</td>\n",
       "      <td>6.0</td>\n",
       "      <td>3.9</td>\n",
       "      <td>1.85</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>34</td>\n",
       "      <td>Male</td>\n",
       "      <td>4.1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>289</td>\n",
       "      <td>875</td>\n",
       "      <td>731</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.7</td>\n",
       "      <td>1.10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>34</td>\n",
       "      <td>Male</td>\n",
       "      <td>4.1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>289</td>\n",
       "      <td>875</td>\n",
       "      <td>731</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.7</td>\n",
       "      <td>1.10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>34</td>\n",
       "      <td>Male</td>\n",
       "      <td>6.2</td>\n",
       "      <td>3.0</td>\n",
       "      <td>240</td>\n",
       "      <td>1680</td>\n",
       "      <td>850</td>\n",
       "      <td>7.2</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.20</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>20</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.5</td>\n",
       "      <td>128</td>\n",
       "      <td>20</td>\n",
       "      <td>30</td>\n",
       "      <td>3.9</td>\n",
       "      <td>1.9</td>\n",
       "      <td>0.95</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>84</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.2</td>\n",
       "      <td>188</td>\n",
       "      <td>13</td>\n",
       "      <td>21</td>\n",
       "      <td>6.0</td>\n",
       "      <td>3.2</td>\n",
       "      <td>1.10</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>553</th>\n",
       "      <td>46</td>\n",
       "      <td>Male</td>\n",
       "      <td>10.2</td>\n",
       "      <td>4.2</td>\n",
       "      <td>232</td>\n",
       "      <td>58</td>\n",
       "      <td>140</td>\n",
       "      <td>7.0</td>\n",
       "      <td>2.7</td>\n",
       "      <td>0.60</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>554</th>\n",
       "      <td>73</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.9</td>\n",
       "      <td>220</td>\n",
       "      <td>20</td>\n",
       "      <td>43</td>\n",
       "      <td>6.5</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.80</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>555</th>\n",
       "      <td>55</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.2</td>\n",
       "      <td>290</td>\n",
       "      <td>139</td>\n",
       "      <td>87</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.70</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>556</th>\n",
       "      <td>51</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.1</td>\n",
       "      <td>180</td>\n",
       "      <td>25</td>\n",
       "      <td>27</td>\n",
       "      <td>6.1</td>\n",
       "      <td>3.1</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>557</th>\n",
       "      <td>51</td>\n",
       "      <td>Male</td>\n",
       "      <td>2.9</td>\n",
       "      <td>1.2</td>\n",
       "      <td>189</td>\n",
       "      <td>80</td>\n",
       "      <td>125</td>\n",
       "      <td>6.2</td>\n",
       "      <td>3.1</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>558</th>\n",
       "      <td>51</td>\n",
       "      <td>Male</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.5</td>\n",
       "      <td>275</td>\n",
       "      <td>382</td>\n",
       "      <td>330</td>\n",
       "      <td>7.5</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>559</th>\n",
       "      <td>26</td>\n",
       "      <td>Male</td>\n",
       "      <td>42.8</td>\n",
       "      <td>19.7</td>\n",
       "      <td>390</td>\n",
       "      <td>75</td>\n",
       "      <td>138</td>\n",
       "      <td>7.5</td>\n",
       "      <td>2.6</td>\n",
       "      <td>0.50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>560</th>\n",
       "      <td>66</td>\n",
       "      <td>Male</td>\n",
       "      <td>15.2</td>\n",
       "      <td>7.7</td>\n",
       "      <td>356</td>\n",
       "      <td>321</td>\n",
       "      <td>562</td>\n",
       "      <td>6.5</td>\n",
       "      <td>2.2</td>\n",
       "      <td>0.40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>561</th>\n",
       "      <td>66</td>\n",
       "      <td>Male</td>\n",
       "      <td>16.6</td>\n",
       "      <td>7.6</td>\n",
       "      <td>315</td>\n",
       "      <td>233</td>\n",
       "      <td>384</td>\n",
       "      <td>6.9</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>562</th>\n",
       "      <td>66</td>\n",
       "      <td>Male</td>\n",
       "      <td>17.3</td>\n",
       "      <td>8.5</td>\n",
       "      <td>388</td>\n",
       "      <td>173</td>\n",
       "      <td>367</td>\n",
       "      <td>7.8</td>\n",
       "      <td>2.6</td>\n",
       "      <td>0.50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>563</th>\n",
       "      <td>64</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.4</td>\n",
       "      <td>0.5</td>\n",
       "      <td>298</td>\n",
       "      <td>31</td>\n",
       "      <td>83</td>\n",
       "      <td>7.2</td>\n",
       "      <td>2.6</td>\n",
       "      <td>0.50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>564</th>\n",
       "      <td>38</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.1</td>\n",
       "      <td>165</td>\n",
       "      <td>22</td>\n",
       "      <td>34</td>\n",
       "      <td>5.9</td>\n",
       "      <td>2.9</td>\n",
       "      <td>0.90</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>565</th>\n",
       "      <td>43</td>\n",
       "      <td>Male</td>\n",
       "      <td>22.5</td>\n",
       "      <td>11.8</td>\n",
       "      <td>143</td>\n",
       "      <td>22</td>\n",
       "      <td>143</td>\n",
       "      <td>6.6</td>\n",
       "      <td>2.1</td>\n",
       "      <td>0.46</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>566</th>\n",
       "      <td>50</td>\n",
       "      <td>Female</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>191</td>\n",
       "      <td>22</td>\n",
       "      <td>31</td>\n",
       "      <td>7.8</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>567</th>\n",
       "      <td>52</td>\n",
       "      <td>Male</td>\n",
       "      <td>2.7</td>\n",
       "      <td>1.4</td>\n",
       "      <td>251</td>\n",
       "      <td>20</td>\n",
       "      <td>40</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1.7</td>\n",
       "      <td>0.39</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>568</th>\n",
       "      <td>20</td>\n",
       "      <td>Female</td>\n",
       "      <td>16.7</td>\n",
       "      <td>8.4</td>\n",
       "      <td>200</td>\n",
       "      <td>91</td>\n",
       "      <td>101</td>\n",
       "      <td>6.9</td>\n",
       "      <td>3.5</td>\n",
       "      <td>1.02</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>569</th>\n",
       "      <td>16</td>\n",
       "      <td>Male</td>\n",
       "      <td>7.7</td>\n",
       "      <td>4.1</td>\n",
       "      <td>268</td>\n",
       "      <td>213</td>\n",
       "      <td>168</td>\n",
       "      <td>7.1</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.20</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>570</th>\n",
       "      <td>16</td>\n",
       "      <td>Male</td>\n",
       "      <td>2.6</td>\n",
       "      <td>1.2</td>\n",
       "      <td>236</td>\n",
       "      <td>131</td>\n",
       "      <td>90</td>\n",
       "      <td>5.4</td>\n",
       "      <td>2.6</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571</th>\n",
       "      <td>90</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.3</td>\n",
       "      <td>215</td>\n",
       "      <td>46</td>\n",
       "      <td>134</td>\n",
       "      <td>6.9</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.70</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>572</th>\n",
       "      <td>32</td>\n",
       "      <td>Male</td>\n",
       "      <td>15.6</td>\n",
       "      <td>9.5</td>\n",
       "      <td>134</td>\n",
       "      <td>54</td>\n",
       "      <td>125</td>\n",
       "      <td>5.6</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>573</th>\n",
       "      <td>32</td>\n",
       "      <td>Male</td>\n",
       "      <td>3.7</td>\n",
       "      <td>1.6</td>\n",
       "      <td>612</td>\n",
       "      <td>50</td>\n",
       "      <td>88</td>\n",
       "      <td>6.2</td>\n",
       "      <td>1.9</td>\n",
       "      <td>0.40</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>574</th>\n",
       "      <td>32</td>\n",
       "      <td>Male</td>\n",
       "      <td>12.1</td>\n",
       "      <td>6.0</td>\n",
       "      <td>515</td>\n",
       "      <td>48</td>\n",
       "      <td>92</td>\n",
       "      <td>6.6</td>\n",
       "      <td>2.4</td>\n",
       "      <td>0.50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>575</th>\n",
       "      <td>32</td>\n",
       "      <td>Male</td>\n",
       "      <td>25.0</td>\n",
       "      <td>13.7</td>\n",
       "      <td>560</td>\n",
       "      <td>41</td>\n",
       "      <td>88</td>\n",
       "      <td>7.9</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2.50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>576</th>\n",
       "      <td>32</td>\n",
       "      <td>Male</td>\n",
       "      <td>15.0</td>\n",
       "      <td>8.2</td>\n",
       "      <td>289</td>\n",
       "      <td>58</td>\n",
       "      <td>80</td>\n",
       "      <td>5.3</td>\n",
       "      <td>2.2</td>\n",
       "      <td>0.70</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>577</th>\n",
       "      <td>32</td>\n",
       "      <td>Male</td>\n",
       "      <td>12.7</td>\n",
       "      <td>8.4</td>\n",
       "      <td>190</td>\n",
       "      <td>28</td>\n",
       "      <td>47</td>\n",
       "      <td>5.4</td>\n",
       "      <td>2.6</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>60</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.1</td>\n",
       "      <td>500</td>\n",
       "      <td>20</td>\n",
       "      <td>34</td>\n",
       "      <td>5.9</td>\n",
       "      <td>1.6</td>\n",
       "      <td>0.37</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>579</th>\n",
       "      <td>40</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.1</td>\n",
       "      <td>98</td>\n",
       "      <td>35</td>\n",
       "      <td>31</td>\n",
       "      <td>6.0</td>\n",
       "      <td>3.2</td>\n",
       "      <td>1.10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580</th>\n",
       "      <td>52</td>\n",
       "      <td>Male</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.2</td>\n",
       "      <td>245</td>\n",
       "      <td>48</td>\n",
       "      <td>49</td>\n",
       "      <td>6.4</td>\n",
       "      <td>3.2</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>581</th>\n",
       "      <td>31</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.3</td>\n",
       "      <td>0.5</td>\n",
       "      <td>184</td>\n",
       "      <td>29</td>\n",
       "      <td>32</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.4</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>582</th>\n",
       "      <td>38</td>\n",
       "      <td>Male</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>216</td>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "      <td>7.3</td>\n",
       "      <td>4.4</td>\n",
       "      <td>1.50</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>583 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Age  Gender  Total_Bilirubin  Direct_Bilirubin  Alkaline_Phosphotase  \\\n",
       "0     65  Female              0.7               0.1                   187   \n",
       "1     62    Male             10.9               5.5                   699   \n",
       "2     62    Male              7.3               4.1                   490   \n",
       "3     58    Male              1.0               0.4                   182   \n",
       "4     72    Male              3.9               2.0                   195   \n",
       "5     46    Male              1.8               0.7                   208   \n",
       "6     26  Female              0.9               0.2                   154   \n",
       "7     29  Female              0.9               0.3                   202   \n",
       "8     17    Male              0.9               0.3                   202   \n",
       "9     55    Male              0.7               0.2                   290   \n",
       "10    57    Male              0.6               0.1                   210   \n",
       "11    72    Male              2.7               1.3                   260   \n",
       "12    64    Male              0.9               0.3                   310   \n",
       "13    74  Female              1.1               0.4                   214   \n",
       "14    61    Male              0.7               0.2                   145   \n",
       "15    25    Male              0.6               0.1                   183   \n",
       "16    38    Male              1.8               0.8                   342   \n",
       "17    33    Male              1.6               0.5                   165   \n",
       "18    40  Female              0.9               0.3                   293   \n",
       "19    40  Female              0.9               0.3                   293   \n",
       "20    51    Male              2.2               1.0                   610   \n",
       "21    51    Male              2.9               1.3                   482   \n",
       "22    62    Male              6.8               3.0                   542   \n",
       "23    40    Male              1.9               1.0                   231   \n",
       "24    63    Male              0.9               0.2                   194   \n",
       "25    34    Male              4.1               2.0                   289   \n",
       "26    34    Male              4.1               2.0                   289   \n",
       "27    34    Male              6.2               3.0                   240   \n",
       "28    20    Male              1.1               0.5                   128   \n",
       "29    84  Female              0.7               0.2                   188   \n",
       "..   ...     ...              ...               ...                   ...   \n",
       "553   46    Male             10.2               4.2                   232   \n",
       "554   73    Male              1.8               0.9                   220   \n",
       "555   55    Male              0.8               0.2                   290   \n",
       "556   51    Male              0.7               0.1                   180   \n",
       "557   51    Male              2.9               1.2                   189   \n",
       "558   51    Male              4.0               2.5                   275   \n",
       "559   26    Male             42.8              19.7                   390   \n",
       "560   66    Male             15.2               7.7                   356   \n",
       "561   66    Male             16.6               7.6                   315   \n",
       "562   66    Male             17.3               8.5                   388   \n",
       "563   64    Male              1.4               0.5                   298   \n",
       "564   38  Female              0.6               0.1                   165   \n",
       "565   43    Male             22.5              11.8                   143   \n",
       "566   50  Female              1.0               0.3                   191   \n",
       "567   52    Male              2.7               1.4                   251   \n",
       "568   20  Female             16.7               8.4                   200   \n",
       "569   16    Male              7.7               4.1                   268   \n",
       "570   16    Male              2.6               1.2                   236   \n",
       "571   90    Male              1.1               0.3                   215   \n",
       "572   32    Male             15.6               9.5                   134   \n",
       "573   32    Male              3.7               1.6                   612   \n",
       "574   32    Male             12.1               6.0                   515   \n",
       "575   32    Male             25.0              13.7                   560   \n",
       "576   32    Male             15.0               8.2                   289   \n",
       "577   32    Male             12.7               8.4                   190   \n",
       "578   60    Male              0.5               0.1                   500   \n",
       "579   40    Male              0.6               0.1                    98   \n",
       "580   52    Male              0.8               0.2                   245   \n",
       "581   31    Male              1.3               0.5                   184   \n",
       "582   38    Male              1.0               0.3                   216   \n",
       "\n",
       "     Alamine_Aminotransferase  Aspartate_Aminotransferase  Total_Protiens  \\\n",
       "0                          16                          18             6.8   \n",
       "1                          64                         100             7.5   \n",
       "2                          60                          68             7.0   \n",
       "3                          14                          20             6.8   \n",
       "4                          27                          59             7.3   \n",
       "5                          19                          14             7.6   \n",
       "6                          16                          12             7.0   \n",
       "7                          14                          11             6.7   \n",
       "8                          22                          19             7.4   \n",
       "9                          53                          58             6.8   \n",
       "10                         51                          59             5.9   \n",
       "11                         31                          56             7.4   \n",
       "12                         61                          58             7.0   \n",
       "13                         22                          30             8.1   \n",
       "14                         53                          41             5.8   \n",
       "15                         91                          53             5.5   \n",
       "16                        168                         441             7.6   \n",
       "17                         15                          23             7.3   \n",
       "18                        232                         245             6.8   \n",
       "19                        232                         245             6.8   \n",
       "20                         17                          28             7.3   \n",
       "21                         22                          34             7.0   \n",
       "22                        116                          66             6.4   \n",
       "23                         16                          55             4.3   \n",
       "24                         52                          45             6.0   \n",
       "25                        875                         731             5.0   \n",
       "26                        875                         731             5.0   \n",
       "27                       1680                         850             7.2   \n",
       "28                         20                          30             3.9   \n",
       "29                         13                          21             6.0   \n",
       "..                        ...                         ...             ...   \n",
       "553                        58                         140             7.0   \n",
       "554                        20                          43             6.5   \n",
       "555                       139                          87             7.0   \n",
       "556                        25                          27             6.1   \n",
       "557                        80                         125             6.2   \n",
       "558                       382                         330             7.5   \n",
       "559                        75                         138             7.5   \n",
       "560                       321                         562             6.5   \n",
       "561                       233                         384             6.9   \n",
       "562                       173                         367             7.8   \n",
       "563                        31                          83             7.2   \n",
       "564                        22                          34             5.9   \n",
       "565                        22                         143             6.6   \n",
       "566                        22                          31             7.8   \n",
       "567                        20                          40             6.0   \n",
       "568                        91                         101             6.9   \n",
       "569                       213                         168             7.1   \n",
       "570                       131                          90             5.4   \n",
       "571                        46                         134             6.9   \n",
       "572                        54                         125             5.6   \n",
       "573                        50                          88             6.2   \n",
       "574                        48                          92             6.6   \n",
       "575                        41                          88             7.9   \n",
       "576                        58                          80             5.3   \n",
       "577                        28                          47             5.4   \n",
       "578                        20                          34             5.9   \n",
       "579                        35                          31             6.0   \n",
       "580                        48                          49             6.4   \n",
       "581                        29                          32             6.8   \n",
       "582                        21                          24             7.3   \n",
       "\n",
       "     Albumin  Albumin_and_Globulin_Ratio  Dataset  \n",
       "0        3.3                        0.90        1  \n",
       "1        3.2                        0.74        1  \n",
       "2        3.3                        0.89        1  \n",
       "3        3.4                        1.00        1  \n",
       "4        2.4                        0.40        1  \n",
       "5        4.4                        1.30        1  \n",
       "6        3.5                        1.00        1  \n",
       "7        3.6                        1.10        1  \n",
       "8        4.1                        1.20        2  \n",
       "9        3.4                        1.00        1  \n",
       "10       2.7                        0.80        1  \n",
       "11       3.0                        0.60        1  \n",
       "12       3.4                        0.90        2  \n",
       "13       4.1                        1.00        1  \n",
       "14       2.7                        0.87        1  \n",
       "15       2.3                        0.70        2  \n",
       "16       4.4                        1.30        1  \n",
       "17       3.5                        0.92        2  \n",
       "18       3.1                        0.80        1  \n",
       "19       3.1                        0.80        1  \n",
       "20       2.6                        0.55        1  \n",
       "21       2.4                        0.50        1  \n",
       "22       3.1                        0.90        1  \n",
       "23       1.6                        0.60        1  \n",
       "24       3.9                        1.85        2  \n",
       "25       2.7                        1.10        1  \n",
       "26       2.7                        1.10        1  \n",
       "27       4.0                        1.20        1  \n",
       "28       1.9                        0.95        2  \n",
       "29       3.2                        1.10        2  \n",
       "..       ...                         ...      ...  \n",
       "553      2.7                        0.60        1  \n",
       "554      3.0                        0.80        1  \n",
       "555      3.0                        0.70        1  \n",
       "556      3.1                        1.00        1  \n",
       "557      3.1                        1.00        1  \n",
       "558      4.0                        1.10        1  \n",
       "559      2.6                        0.50        1  \n",
       "560      2.2                        0.40        1  \n",
       "561      2.0                        0.40        1  \n",
       "562      2.6                        0.50        1  \n",
       "563      2.6                        0.50        1  \n",
       "564      2.9                        0.90        2  \n",
       "565      2.1                        0.46        1  \n",
       "566      4.0                        1.00        2  \n",
       "567      1.7                        0.39        1  \n",
       "568      3.5                        1.02        1  \n",
       "569      4.0                        1.20        1  \n",
       "570      2.6                        0.90        1  \n",
       "571      3.0                        0.70        1  \n",
       "572      4.0                        2.50        1  \n",
       "573      1.9                        0.40        1  \n",
       "574      2.4                        0.50        1  \n",
       "575      2.5                        2.50        1  \n",
       "576      2.2                        0.70        1  \n",
       "577      2.6                        0.90        1  \n",
       "578      1.6                        0.37        2  \n",
       "579      3.2                        1.10        1  \n",
       "580      3.2                        1.00        1  \n",
       "581      3.4                        1.00        1  \n",
       "582      4.4                        1.50        2  \n",
       "\n",
       "[583 rows x 11 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "data = pd.read_csv(\"data.csv\")   # Reading data csv file\n",
    "labels = data['Dataset']         # Setting the labels\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we can see below, there are 9 columns, each with largely different ranges. We can observe that there are a total of 583 data points."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Age</th>\n",
       "      <th>Total_Bilirubin</th>\n",
       "      <th>Direct_Bilirubin</th>\n",
       "      <th>Alkaline_Phosphotase</th>\n",
       "      <th>Alamine_Aminotransferase</th>\n",
       "      <th>Aspartate_Aminotransferase</th>\n",
       "      <th>Total_Protiens</th>\n",
       "      <th>Albumin</th>\n",
       "      <th>Albumin_and_Globulin_Ratio</th>\n",
       "      <th>Dataset</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>583.000000</td>\n",
       "      <td>583.000000</td>\n",
       "      <td>583.000000</td>\n",
       "      <td>583.000000</td>\n",
       "      <td>583.000000</td>\n",
       "      <td>583.000000</td>\n",
       "      <td>583.000000</td>\n",
       "      <td>583.000000</td>\n",
       "      <td>579.000000</td>\n",
       "      <td>583.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>44.746141</td>\n",
       "      <td>3.298799</td>\n",
       "      <td>1.486106</td>\n",
       "      <td>290.576329</td>\n",
       "      <td>80.713551</td>\n",
       "      <td>109.910806</td>\n",
       "      <td>6.483190</td>\n",
       "      <td>3.141852</td>\n",
       "      <td>0.947064</td>\n",
       "      <td>1.286449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>16.189833</td>\n",
       "      <td>6.209522</td>\n",
       "      <td>2.808498</td>\n",
       "      <td>242.937989</td>\n",
       "      <td>182.620356</td>\n",
       "      <td>288.918529</td>\n",
       "      <td>1.085451</td>\n",
       "      <td>0.795519</td>\n",
       "      <td>0.319592</td>\n",
       "      <td>0.452490</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>4.000000</td>\n",
       "      <td>0.400000</td>\n",
       "      <td>0.100000</td>\n",
       "      <td>63.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>2.700000</td>\n",
       "      <td>0.900000</td>\n",
       "      <td>0.300000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>33.000000</td>\n",
       "      <td>0.800000</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>175.500000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>5.800000</td>\n",
       "      <td>2.600000</td>\n",
       "      <td>0.700000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>45.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.300000</td>\n",
       "      <td>208.000000</td>\n",
       "      <td>35.000000</td>\n",
       "      <td>42.000000</td>\n",
       "      <td>6.600000</td>\n",
       "      <td>3.100000</td>\n",
       "      <td>0.930000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>58.000000</td>\n",
       "      <td>2.600000</td>\n",
       "      <td>1.300000</td>\n",
       "      <td>298.000000</td>\n",
       "      <td>60.500000</td>\n",
       "      <td>87.000000</td>\n",
       "      <td>7.200000</td>\n",
       "      <td>3.800000</td>\n",
       "      <td>1.100000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>90.000000</td>\n",
       "      <td>75.000000</td>\n",
       "      <td>19.700000</td>\n",
       "      <td>2110.000000</td>\n",
       "      <td>2000.000000</td>\n",
       "      <td>4929.000000</td>\n",
       "      <td>9.600000</td>\n",
       "      <td>5.500000</td>\n",
       "      <td>2.800000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Age  Total_Bilirubin  Direct_Bilirubin  Alkaline_Phosphotase  \\\n",
       "count  583.000000       583.000000        583.000000            583.000000   \n",
       "mean    44.746141         3.298799          1.486106            290.576329   \n",
       "std     16.189833         6.209522          2.808498            242.937989   \n",
       "min      4.000000         0.400000          0.100000             63.000000   \n",
       "25%     33.000000         0.800000          0.200000            175.500000   \n",
       "50%     45.000000         1.000000          0.300000            208.000000   \n",
       "75%     58.000000         2.600000          1.300000            298.000000   \n",
       "max     90.000000        75.000000         19.700000           2110.000000   \n",
       "\n",
       "       Alamine_Aminotransferase  Aspartate_Aminotransferase  Total_Protiens  \\\n",
       "count                583.000000                  583.000000      583.000000   \n",
       "mean                  80.713551                  109.910806        6.483190   \n",
       "std                  182.620356                  288.918529        1.085451   \n",
       "min                   10.000000                   10.000000        2.700000   \n",
       "25%                   23.000000                   25.000000        5.800000   \n",
       "50%                   35.000000                   42.000000        6.600000   \n",
       "75%                   60.500000                   87.000000        7.200000   \n",
       "max                 2000.000000                 4929.000000        9.600000   \n",
       "\n",
       "          Albumin  Albumin_and_Globulin_Ratio     Dataset  \n",
       "count  583.000000                  579.000000  583.000000  \n",
       "mean     3.141852                    0.947064    1.286449  \n",
       "std      0.795519                    0.319592    0.452490  \n",
       "min      0.900000                    0.300000    1.000000  \n",
       "25%      2.600000                    0.700000    1.000000  \n",
       "50%      3.100000                    0.930000    1.000000  \n",
       "75%      3.800000                    1.100000    2.000000  \n",
       "max      5.500000                    2.800000    2.000000  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 583 entries, 0 to 582\n",
      "Data columns (total 11 columns):\n",
      "Age                           583 non-null int64\n",
      "Gender                        583 non-null object\n",
      "Total_Bilirubin               583 non-null float64\n",
      "Direct_Bilirubin              583 non-null float64\n",
      "Alkaline_Phosphotase          583 non-null int64\n",
      "Alamine_Aminotransferase      583 non-null int64\n",
      "Aspartate_Aminotransferase    583 non-null int64\n",
      "Total_Protiens                583 non-null float64\n",
      "Albumin                       583 non-null float64\n",
      "Albumin_and_Globulin_Ratio    579 non-null float64\n",
      "Dataset                       583 non-null int64\n",
      "dtypes: float64(5), int64(5), object(1)\n",
      "memory usage: 50.2+ KB\n"
     ]
    }
   ],
   "source": [
    "# Like Describe above other commands for exploring dataset are:\n",
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Age</th>\n",
       "      <th>Gender</th>\n",
       "      <th>Total_Bilirubin</th>\n",
       "      <th>Direct_Bilirubin</th>\n",
       "      <th>Alkaline_Phosphotase</th>\n",
       "      <th>Alamine_Aminotransferase</th>\n",
       "      <th>Aspartate_Aminotransferase</th>\n",
       "      <th>Total_Protiens</th>\n",
       "      <th>Albumin</th>\n",
       "      <th>Albumin_and_Globulin_Ratio</th>\n",
       "      <th>Dataset</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>65</td>\n",
       "      <td>Female</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.1</td>\n",
       "      <td>187</td>\n",
       "      <td>16</td>\n",
       "      <td>18</td>\n",
       "      <td>6.8</td>\n",
       "      <td>3.3</td>\n",
       "      <td>0.90</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>62</td>\n",
       "      <td>Male</td>\n",
       "      <td>10.9</td>\n",
       "      <td>5.5</td>\n",
       "      <td>699</td>\n",
       "      <td>64</td>\n",
       "      <td>100</td>\n",
       "      <td>7.5</td>\n",
       "      <td>3.2</td>\n",
       "      <td>0.74</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>62</td>\n",
       "      <td>Male</td>\n",
       "      <td>7.3</td>\n",
       "      <td>4.1</td>\n",
       "      <td>490</td>\n",
       "      <td>60</td>\n",
       "      <td>68</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.3</td>\n",
       "      <td>0.89</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Age  Gender  Total_Bilirubin  Direct_Bilirubin  Alkaline_Phosphotase  \\\n",
       "0   65  Female              0.7               0.1                   187   \n",
       "1   62    Male             10.9               5.5                   699   \n",
       "2   62    Male              7.3               4.1                   490   \n",
       "\n",
       "   Alamine_Aminotransferase  Aspartate_Aminotransferase  Total_Protiens  \\\n",
       "0                        16                          18             6.8   \n",
       "1                        64                         100             7.5   \n",
       "2                        60                          68             7.0   \n",
       "\n",
       "   Albumin  Albumin_and_Globulin_Ratio  Dataset  \n",
       "0      3.3                        0.90        1  \n",
       "1      3.2                        0.74        1  \n",
       "2      3.3                        0.89        1  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(n=3) # By default n is 5. It gives the first n rows.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Task 1: Querying the dataset\n",
    "\n",
    "In order to get a certain idea of how the dataset is distributed, we can try querying the dataset."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With Pandas you can do almost anything that you can do in SQL (if you are familiar with SQL, e.g., you have seen this kind of thing in a database course). Commands like groupby, join, concatenation, merging, etc. It is also possible to write subqueries and joins in Pandas. See the following queries for a sort of SQL query. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of patients who are male and are less than 20 years old: 29\n"
     ]
    }
   ],
   "source": [
    "no_patients = len(data[(data['Gender']=='Male') & (data['Age']<20)])\n",
    "print(\"Number of patients who are male and are less than 20 years old: {}\"\n",
    "      .format(no_patients))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here are some queries for you to practice. Also note the way the print statement with format has been written, which may  be useful in future. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q1. Print the number of male patients and number of female patients"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO\n",
    "no_males = None #Fill this\n",
    "no_females = None #Fill this\n",
    "\n",
    "print(\"Number of male patients: {}\".format(no_males))\n",
    "print(\"Number of male patients: {}\".format(no_females))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q2. Print the number of patients who are older than 50 and have a level of Direct_Bilirubin above 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO\n",
    "no_patients = None\n",
    "print(\"Number of patients who are older than 50 and have a level of Direct_Bilirubin above 0.5: {}\"\n",
    "      .format(no_patients))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q3. Print a dataframe of patients who are younger than 32 or have a level of Alkaline_Phosphotase below 200"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO\n",
    "patients = None\n",
    "\n",
    "patients"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Feel free to try out some other queries here. The way above queries have been written try something out on the same lines :"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Task 2: Data Visualization\n",
    "\n",
    "Sometimes querying isn't enough, and you need to see the data laid out to understand more. Seaborn is a library which is a wrapper over matplotlib and is extremely convenient to use. For example, the below plot shows a box plot of alkaline_phosphotase of all patients."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/pratik/.local/lib/python3.5/site-packages/seaborn/categorical.py:454: FutureWarning: remove_na is deprecated and is a private function. Do not use.\n",
      "  box_data = remove_na(group_data)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcwAAAFYCAYAAADeLMzTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAF2tJREFUeJzt3X9U1fUdx/HXBUTkhD8R0m0eK7XYDrqk5jHPWrpGWwsx\nj1o5aHV0tTP1NDePkrKk0onKtJ3mOWnR5nBtNnJiG7lstuZxyBoupI6bx+MoU5eICwQECT77w927\ne5GLb/B6+bHn45+83/v98bn3c29PvvdeuB7nnBMAAOhQRHcPAACA3oBgAgBgQDABADA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SoszMTGVmZmrOnDnKyclRc3OzJOnGG2/UJ598EtJj\nen344Ye6/fbbO7XNwYMHfb/bCPy/I5joE3bu3KkbbrhBO3bsCNk+k5KS9IMf/CBk+/MaN26cCgoK\nVFBQoO3bt+vjjz/W9u3bQ36cUNixYwfBBP4rJH9LFuhur7zyinJycpSVlaWDBw9q4sSJ7a63f/9+\nbdy4UT/96U914MABvfDCC4qOjlZLS4vWrVunT3/60751S0tL9cwzz+iXv/ylMjMzNXnyZP3tb39T\nZWWlFi1apOnTp6umpkYrV67U2bNnVVdXp4cfflhpaWnmcXs8HqWkpOjYsWO+ZQUFBdq7d6+qq6u1\nYcMG3XTTTSovL1dubq6ioqLk8Xj0xBNPaMyYMdq6dat27dqlAQMGKCYmRuvXr9eRI0f0zDPPaOTI\nkTpx4oTi4uK0ceNG3/43btyot99+Ww0NDdq8ebMSExP1xz/+UZs2bVJMTIwGDBigp59+WocOHdLu\n3bt16NAhPf744+rXr5/y8vIUHR2txsZGrVy5Up/73OdUXFys/Px8xcbGyjnn+z7D4uJibdu2Tc45\nDR06VKtWrQr40gag1wnvt4kBofeXv/zFTZs2zbW2troNGza4FStWOOecmzp1qqusrHSvvPKK+/73\nv+8OHz7sZsyY4aqqqpxzzhUWFroTJ04455x77rnnXG5urnPOuYyMDLd//3534MABd//99/uWrV+/\n3jl38ftg09LSnHPO5eTkuMLCQufcxe9evPPOO111dXXQsfrv0znnGhsb3cMPP+x+97vfOeecGzdu\nnHvrrbecc85t2rTJPfXUU84551JTU115eblzzrm9e/e6jIwM55xzEydO9N2eP/3pT+7vf/+7O3Dg\ngEtOTnb/+te/nHPOLVmyxG3dutUdP37cJSUluX/84x/OOeeWL1/u8vPzXUNDg5syZYo7deqUc865\ngoICl5WVFXBfOOfcnj173OHDh51zzr366qu+72dNS0tz77zzjnPOuXfeece9/fbb7uTJky4tLc01\nNTU555z72c9+5tasWXOZmQR6Ns4w0esVFhbq3nvvlcfj0cyZMzVz5kytWLEiYJ2PPvpIjzzy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mjDZs2KD3339fgwYN0owZM3T27Nl29x0TE6PVq1dr8eLFio6OVmxs\nrFavXi3p4lf5rVy5UsuXL9e3vvUtffOb3wy4vwoKCjRkyBDdf//9GjhwoCQpOztbiYmJWrFihR59\n9FHfB5LWrl0b8vsFCCe+rQToY/w/3QsgdDjDBEJsz549+vnPf97udR29dwmgZ+MMEwAAAz70AwCA\nAcEEAMCAYAIAYEAwAQAwIJgAABgQTAAADP4DRl1CVu2JZKwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f0a85aa8a20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "sns.set_style(\"whitegrid\")\n",
    "\n",
    "sns.boxplot(x=data['Alkaline_Phosphotase']) #Box plot\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q4. Using seaborn, plot a scatter plot between Age and Total_Protiens (note that this is mispelled in the dataset)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO\n",
    "\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q5. Plot a grouped bar chart comparing the Alamine_Aminotransferase levels of patients with liver disease and patients without liver disease, categorized by gender. (Hint: Use the hue property of barplot for gender, and check this out: https://seaborn.pydata.org/generated/seaborn.barplot.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's view the correlation heatmap for the different features for some more inspiration. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'plt' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-8-0ef81ac754bc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      8\u001b[0m \u001b[0;31m# Set up the matplotlib figure\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0max\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubplots\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m11\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m9\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     11\u001b[0m \u001b[0;31m# Generate a custom diverging colormap\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'plt' is not defined"
     ]
    }
   ],
   "source": [
    "# Compute the correlation matrix\n",
    "corr = data.corr()\n",
    "\n",
    "# Generate a mask for the upper triangle\n",
    "mask = np.zeros_like(corr, dtype=np.bool)\n",
    "mask[np.triu_indices_from(mask)] = True\n",
    "\n",
    "# Set up the matplotlib figure\n",
    "f, ax = plt.subplots(figsize=(11, 9))\n",
    "\n",
    "# Generate a custom diverging colormap\n",
    "cmap = sns.diverging_palette(220, 10, as_cmap=True)\n",
    "\n",
    "# Draw the heatmap with the mask and correct aspect ratio\n",
    "sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,\n",
    "            square=True, linewidths=.5, cbar_kws={\"shrink\": .5})\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q6. You can try out any other plots here:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Feature Selection and Scaling"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "According to the knowledge that we've gathered above, let's decide on the best features that we should include for creating a model. Using the knowledge that you have about dimensionality and feature selection, pick an appropriate number of features for the dataset. There is no right or wrong here."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Task 3: Feature Selection\n",
    "\n",
    "Q7. Make a reduced dataset new_data by selecting only relevant columns from the original dataframe."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#TODO \n",
    "\n",
    "new_data = None\n",
    "\n",
    "new_data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Task 4: Create Training and Validation Data Split\n",
    "\n",
    "Q8. Create training and validation split on data. Check out train_test_split() function from sklearn to do this."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "#TODO\n",
    "X_train,X_val,y_train,y_val = None\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Task 5: Feature Scaling\n",
    "\n",
    "We always scale the features after splitting the dataset because we want to ensure that the validation data is isolated. This is because the validation data acts as new, unseen data. Any transformation on it will reduce its validity.\n",
    "\n",
    "Q9. Although there are many methods to scale data, let's use MinMaxScaler from sklearn. Scale the training data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import MinMaxScaler\n",
    "\n",
    "#TODO\n",
    "scaler = None             #Instantiate the scaler\n",
    "scaled_X_train = None     #Fit and transform the data\n",
    "\n",
    "scaled_X_train"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Task 6: Model Creation\n",
    "\n",
    "Now we are finally ready to create a model and train it. Remember that this is a two-class classification problem. We need to select a classifier, not a regressor. Let's analyze two simple models, DecisionTreeClassifier and Gaussian Naive Bayes Classifier. We will cover both of these models in more depth later on in the course, for now, have a read of the following articles that give explanations of how to implement both models in scikitlearn:\n",
    "\n",
    "Decision Trees: https://www.datacamp.com/community/tutorials/decision-tree-classification-python\n",
    "\n",
    "Naive Bayes: https://www.datacamp.com/community/tutorials/naive-bayes-scikit-learn"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q10. Instantiate and train a DecisionTreeClassifier on the given data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "#TODO\n",
    "clf_dt = None                #Instantiate a DecisionTreeClassifier model and fit it to the training data using fit function"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q11. Instantiate and train a GaussianNB on the given data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.naive_bayes import GaussianNB\n",
    "#TODO\n",
    "clf_nb = None                #Instantiate a DecisionTreeClassifier model and fit it to the training data using fit function"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Model Evaluation\n",
    "\n",
    "These models are now capable of 'predicting' whether a patient has liver disease or not. But we need to evaluate their performance. Since it is a two-class classification problem, we can use accuracy. However, let us also use some additional metrics for better analysis, precision,recall, and f1score."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Task 7: Performance Metrics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q12. Using the accuracy_score function, determine the accuracy of the two classifiers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "#TODO\n",
    "scaled_X_val = None                  #Fit and transform the validation set using the MinMaxScaler\n",
    "\n",
    "y_pred_dt = clf_dt.predict(scaled_X_val)\n",
    "y_pred_nb = clf_nb.predict(scaled_X_val)                      \n",
    "\n",
    "#Use accuracy score and determine accuracy of both classifiers\n",
    "acc_dt = None                            \n",
    "acc_nb = None\n",
    "\n",
    "print(\"The accuracy of Decision Tree: {} %\".format(acc_dt))\n",
    "print(\"The accuracy of Gaussian Naive Bayes: {} %\".format(acc_nb))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q13. Determine the precision and recall using precision_score and recall_score."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import precision_score,recall_score\n",
    "#TODO\n",
    "prec_dt = None\n",
    "prec_nb = None\n",
    "\n",
    "recall_dt = None\n",
    "recall_nb = None\n",
    "\n",
    "print(\"The precision of Decision Tree: {} %\".format(prec_dt))\n",
    "print(\"The precision of Gaussian Naive Bayes: {} %\".format(prec_nb))\n",
    "print(\"The recall of Decision Tree: {} %\".format(recall_dt))\n",
    "print(\"The recall of Gaussian Naive Bayes: {} %\".format(recall_nb))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q14. Determine the F1-score of the two classifiers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.metrics import f1_score\n",
    "\n",
    "f1_dt = None\n",
    "f1_nb = None\n",
    "\n",
    "print(\"The F1-score of Decision Tree: {} %\".format(f1_dt))\n",
    "print(\"The F1-score of Gaussian Naive Bayes: {} %\".format(f1_nb))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We have officially solved a machine learning problem. However, the question of making an effective model is still in question.Try to get the f1 score of any of the classifiers to 85%. Try to use some other scalers if need be. You can experiment with some other data cleaning techniques like outlier removal. You can try using other classifiers, but remember that in the end, no matter how good the classifier, if the data quality sucks, the performance will not be optimum."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
